define(function(require){
	var $=require("jq");
	
	/*$.getJSON("/getLoginAdv.do",function(result){
		$('#login-box').attr('style',"background :url("+result['picsPath']+") no-repeat");
	});*/
	
	function ValidateLogin(obj){
		var _this_=this;
		//验证区域
		this.validateForm=$("form",obj);
		//保存提示
		this.tipsBox=$("#warning",obj);
		//用户名
		this.userName=$("#userName",obj);
		//密码
		this.password=$("#userPassword",obj);
		//验证码
		this.validateCode=$("#validateCode",obj);
		//看不清，换一张
		this.changePic=$(".validate-code-pic",obj);
		//保存一周免登录
		this.oneWeekFree=$("#oneWeek",obj);
		this.oneWeekFree.click(function(){
			if(this.checked){
				this.value="yes";
			}else{
				this.value="no";
			};
		});
		//登录按钮
		this.loginBtn=$(".submit-btn",obj);
		//用户名
		this.userName.focus(function(){
			$(this).addClass("focus");
			_this_.slideTips(true);
		}).blur(function(){
			$(this).removeClass("focus");
		}).val("");
		//密码框
		this.password.focus(function(){
			$(this).addClass("focus");
			_this_.slideTips(true);
		}).blur(function(){
			$(this).removeClass("focus");
		}).val("");
		//验证码焦点
		this.validateCode.focus(function(){
			$(this).addClass("focus");
			_this_.slideTips(true);
		}).blur(function(){
			$(this).removeClass("focus");
		}).val("")
		//切换验证码click
		this.changePic.click(function(){
			$("img",this).attr("src","/validateCode?random="+Math.random());
		});
		//登录click
		this.loginBtn.click(function(e){
			//e.preventDefault();
			_this_.login();
		});
		$(document).keypress(function(e){
			if(e.which==13){
				_this_.loginBtn.click();
			};
		});
	};
	ValidateLogin.prototype={
		login:function(){
			if($.trim(this.userName.val())==""){
				this.slideTips(false,"用户名不能为空,请重新输入用户名！");
				this.userName.addClass("focus");
				return;
			};
			if($.trim(this.password.val())==""){
				this.slideTips(false,"密码不能为空,请重新输入密码！");
				this.password.addClass("focus");
				return;
			};
			/*if($.trim(this.validateCode.val())==""){
				this.slideTips(false,"请输入4位数验证码,看不清换一张试试！");
				this.validateCode.addClass("focus");
				return;
			};*/
			//验证码
			this.goValidateCode(this.validateCode.val());
		},
		goValidateCode:function(v){
			var $this=this;
//			$.post("/loginCode.do",{validateCode:v},function(ret){
//				if(ret.state=="success"){
//					/*-------------------------验证接口---------------------------------------*/
//					$.post("/loginOk.do",{userName:$.trim($this.userName.val()),password:$this.password.val(),validateCode:$this.validateCode.val(),disLogin:$this.oneWeekFree.val()},function(ret){
//						if(ret.state=="success"){
//							var url=$this.validateForm.attr("data-tourl")||"/";
//							window.location=url;
//						}else{
//							$this.slideTips(false,ret.msg);
//							$this.changePic.click();
//						};
//					},"json");
//				}else if(ret.state=="error"){
//					$this.slideTips(false,"请输入4位数验证码,看不清换一张试试！");
//					$this.changePic.click();
//				};
//			},"json");
			
			$.post("/loginOk.do",{userName:$.trim($this.userName.val()),password:$this.password.val(),validateCode:$this.validateCode.val(),disLogin:$this.oneWeekFree.val()},function(ret){
				if(ret.state=="success"){
					var url=$this.validateForm.attr("data-tourl")||"/front/flight/index.jsp";
//					_czc.push(["_setCustomVar","是否登录","已登录",3600]);
//					if(ret.isVip >= 100){
//						_czc.push(["_setCustomVar","会员级别","VIP会员",1]);
//					} else _czc.push(["_setCustomVar","会员级别","普通会员",1]);
					window.location=url;
				}else{
					$this.slideTips(false,ret.msg);
					$this.changePic.click();
				};
			},"json");
		},
		slideTips:function(isOk,text){
			if(isOk){
				this.tipsBox.slideUp(function(){
					$(this).find("strong").text(text/*"您输入的用户名或密码错误,请重新输入！"*/);
				});
			}else{
				if(!text){
					this.tipsBox.slideDown();
				}else{
					this.tipsBox.find("strong").text(text/*"您输入的验证码错误,换一张再试试！"*/);
					this.tipsBox.slideDown();
				}
			};
		}
	};
	//传入验证区域和请求地址
	var validateLogin=new ValidateLogin("#validate-login");
});